package it.uniroma2.structure;

public class CopyParameter extends Copy{
	private Parameter from;
	private Parameter to;
//	private Literal literal;
	private final String queryTag = "<bpel:query queryLanguage=\"urn:oasis:names:tc:wsbpel:2.0:sublang:xpath1.0\"><![CDATA[";
	private final String queryTagClose = "]]></bpel:query>";
	private Variable toVar;
	
	public CopyParameter(Parameter from, Parameter to){
//		this.literal = null;
		this.from = from;
		this.to = to;
	}
	
	
	@Override
	public boolean equals(Object obj) {
		if(((CopyParameter)obj).getFromVariable().equals(this.from) && ((CopyParameter)obj).getToVariable().equals(this.to)){
			return true;
		}else{
			return false;
		}
	}
	
	
	private Object getToVariable() {
		return this.to;
	}


	private Object getFromVariable() {
		return this.from;
	}


	@Override
	public String toBPEL() {
		String output = "";
		output = output + "<" + copyTag + ">\n";
		output = output + "<" + fromTag ;
//		if(this.literal != null){
//			output = output + ">\n";
//			this.literal.toBPEL();
//		}else{
			if(this.from.getVariable() instanceof VariableService){
				output = output + " variable=\"" + this.from.getVariable().getName() + "\" part=\"" + ((VariableService)this.from.getVariable()).getPart() + "\">\n";
				output = output + this.queryTag + ((VariableService)this.from.getVariable()).getNamespace() + ":" + this.from.getName() + this.queryTagClose + "\n";
			}else{
				output = output + " variable=\"" + this.from.getVariable().getName() + "\" part=\"" + ((VariableProcess)this.from.getVariable()).getPart() + "\">\n";
				output = output + this.queryTag + ((VariableProcess)this.from.getVariable()).getPrefix() + ":" + this.from.getName() + this.queryTagClose + "\n";
			}
			
					
//		}
		output = output + "</" + fromTag + ">\n";
		if(this.to.getVariable() instanceof VariableService){
			output = output + "<" + toTag + " variable=\"" + this.to.getVariable().getName() + "\" part=\"" + ((VariableService)this.to.getVariable()).getPart() + "\">\n";
			output = output + this.queryTag + ((VariableService)this.to.getVariable()).getNamespace() + ":" + this.to.getName() + this.queryTagClose + "\n";
		}else{
			output = output + "<" + toTag + " variable=\"" + this.to.getVariable().getName() + "\" part=\"" + ((VariableProcess)this.to.getVariable()).getPart() + "\">\n";
			output = output + this.queryTag + ((VariableProcess)this.to.getVariable()).getPrefix() + ":" + this.to.getName() + this.queryTagClose + "\n";
		}
		
		output = output + "</" + toTag + ">\n";
		output = output + "</" + copyTag + ">\n";
		return output;
	}


	public Parameter getParamFrom() {
		return from;
	}


	public Parameter getParamTo() {
		return to;
	}


	public void setFrom(Parameter from) {
		this.from = from;
	}


	public void setTo(Parameter to) {
		this.to = to;
	}

}
